#include "FramelessWidget.h"
#include <QPainter>
#include <qpoint.h>
#include <QRandomGenerator>
namespace UserManagementSystem {
FramelessWidget::FramelessWidget(QWidget* parent)
    :QWidget(parent)
{
    qDebug()<<__FUNCTION__;
    //设置窗口的默认大小
    // this->showMaximized();

    //设置窗口为无边框
    this->SetDefaultStyle();



}

void FramelessWidget::SetPosition(const QPoint pos, const QSize size)
{
    //重新设置窗口的起始点和大小
    qDebug()<<__FUNCTION__;
    this->move(pos.x(),pos.y());
    this->resize(size);
}





void FramelessWidget::SetBackGround(const QColor color)
{

}

void FramelessWidget::SetDefaultStyle()
{
    //设置无边框，透明背景
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::Window|Qt::CustomizeWindowHint);
}

void FramelessWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    painter.setRenderHint(QPainter::Antialiasing);

    int r,g,b,i;
    r=QRandomGenerator::global()->bounded(0,255);
    g=QRandomGenerator::global()->bounded(0,255);
    b=QRandomGenerator::global()->bounded(0,255);
    i=QRandomGenerator::global()->bounded(100,255);

    QColor blue(r,g,b,i);//带透明度的蓝色
    painter.setBrush(blue);
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(this->rect(),20,20);
}
};

